package com.zhilei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhilei.mapper.CompanyPhotoMapper;
import com.zhilei.pojo.CompanyPhoto;
import com.zhilei.service.CompanyPhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 企业相册表，本表只存企业上传的图片 服务实现类
 * </p>
 *
 * @author 王志磊
 * @since 2024-09-29
 */
@Service
public class CompanyPhotoServiceImpl extends ServiceImpl<CompanyPhotoMapper, CompanyPhoto> implements CompanyPhotoService {

    @Autowired
    private CompanyPhotoMapper companyPhotoMapper;

    /**
     * 保存企业相册到企业相册表
     *
     * @param companyId
     */
    @Transactional
    @Override
    public void savePhoto(String companyId, String photos) {
        CompanyPhoto companyPhoto = new CompanyPhoto();
        companyPhoto.setCompanyId(companyId);
        companyPhoto.setPhotos(photos);
        // 全删全增
        companyPhotoMapper.delete(new QueryWrapper<CompanyPhoto>().eq("company_id", companyId));
        companyPhotoMapper.insert(companyPhoto);
    }
}
